@ECHO.
@ECHO Building the project...

:: Change Build configuration here
@SET BuildConf=Release

:: ProjectRoot is directory under which your entire solution is stored.
:: All directory, solution and project names are for illustrative purpose. You can change it as per your need.
@SET ProjectRoot=My.Project
:: SolutionName is name of within ProjectRoot solution 
@SET SolutionName=My.Project.sln
:: Below are common BizTalk projects
@SET ComponentsName=My.Project.Components
@SET OrchestrationsName=My.Project.Orchestrations
@SET PipelineComponentsName=My.Project.PipelineComponents
@SET PipelinesName=My.Project.Pipelines
@SET SchemasName=My.Project.Schemas
@SET TransformsName=My.Project.Transforms
:: BindingFileDirectory is where all bindings are kept. Directory name should be BindingFile as below. If you have different name, then change here.
@SET BindingFileDirectory=.\%ProjectRoot%\BindingFile
:: Name of biding files for different environments e.g. Dev, Sys, Test, Prelive, Live
@SET DevBinding=My.Project.BindingInfo.Dev
@SET SysBinding=My.Project.BindingInfo.Sys
@SET TestBinding=My.Project.BindingInfo.Test
@SET PreliveBinding=My.Project.BindingInfo.Prelive
@SET LiveBinding=My.Project.BindingInfo.Live
:: SSO Application directory
@SET SSOApplicationDir=.\%PaymentsHubRoot%\SSOApplication
:: BizTalk Rule Engine artefacts
@SET BRE=.\%PaymentsHubRoot%\BRE
:: COM+ application artefacts
@SET COMApplication=.\%PaymentsHubRoot%\ComApplication

:: Binary directory where all deployable components will be stored
@SET BINDirectory=Bin
:: Setting MSBuild path from registry
SET MSBUILDINSTALL=
for /D %%D in (%SYSTEMROOT%\Microsoft.NET\Framework\v4*) DO SET MSBUILDINSTALL=%%D
echo %MSBUILDINSTALL%
:: Building project with build configuration. You can change target from Build to Rebuild as well
%MSBUILDINSTALL%\msbuild.exe ".\%ProjectRoot%\%SolutionName%" /t:Build /p:Configuration=%BuildConf% 
:: Creates a Bin directory where build dlls would be copied
MKDIR %BINDirectory%
:: BizTalk root directory read from registry
SET BIZINSTALLATION=
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\BizTalk Server\3.0" /v InstallPath') DO SET BIZINSTALLATION=%%B
echo %BIZINSTALLATION%

:: Copying DLLs from directory built from to Bin directory
:: Assumption is dll name is same as that of project name, which true by default. 
:: If you have made change in DLL name from project properties then make that change here.
@ECHO Copy DLLs to Bin Directory...
@Set DestinationPath=%BINDirectory%
@SET SourcePath=".\%ProjectRoot%\%ComponentsName%\bin\%BuildConf%\%ComponentsName%.dll" 
XCOPY %SourcePath% %DestinationPath% /Y /R
@SET SourcePath=".\%ProjectRoot%\%PipelineComponentsName%\bin\%BuildConf%\%PipelineComponentsName%.dll" 
XCOPY %SourcePath% %DestinationPath% /Y /R
@SET SourcePath=".\%ProjectRoot%\%SchemasName%\bin\%BuildConf%\%SchemasName%.dll" 
XCOPY %SourcePath% %DestinationPath% /Y /R
@SET SourcePath=".\%ProjectRoot%\%TransformsName%\bin\%BuildConf%\%TransformsName%.dll" 
XCOPY %SourcePath% %DestinationPath% /Y /R
@SET SourcePath=".\%ProjectRoot%\%PipelinesName%\bin\%BuildConf%\%PipelinesName%.dll" 
XCOPY %SourcePath% %DestinationPath% /Y /R
@SET SourcePath=".\%ProjectRoot%\%OrchestrationsName%\bin\%BuildConf%\%OrchestrationsName%.dll" 
XCOPY %SourcePath% %DestinationPath% /Y /R

:: Copying Pipeline Component DLL to BizTalk Pipeline Component directory
@SET SourcePath=".\%ProjectRoot%\%PipelineComponentsName%\bin\%BuildConf%\%PipelineComponentsName%.dll" 
@Set DestinationPath="%BIZINSTALLATION%\Pipeline Components"
XCOPY %SourcePath% %DestinationPath% /Y /R
@Set DestinationPath=%BINDirectory%

:: Copying Binding files to Bin directory
@SET SourcePath="%BindingFileDirectory%\%DevBinding%.xml"
XCOPY %SourcePath% %DestinationPath% /Y /R
@SET SourcePath="%BindingFileDirectory%\%SysBinding%.xml"
XCOPY %SourcePath% %DestinationPath% /Y /R
@SET SourcePath="%BindingFileDirectory%\%TestBinding%.xml"
XCOPY %SourcePath% %DestinationPath% /Y /R
@SET SourcePath="%BindingFileDirectory%\%PreliveBinding%.xml"
XCOPY %SourcePath% %DestinationPath% /Y /R
@SET SourcePath="%BindingFileDirectory%\%LiveBinding%.xml"
XCOPY %SourcePath% %DestinationPath% /Y /R

@SET SourcePath="%ComApplication%\*.*"
XCOPY %SourcePath% %DestinationPath% /Y /R

@SET SourcePath="%BRE%\*.*"
XCOPY %SourcePath% %DestinationPath% /Y /R

@SET SourcePath="%SSOApplicationDir%\*.*"
XCOPY %SourcePath% %DestinationPath% /Y /R

pause;